package vaani.internal.actionmanagers;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import vaani.internal.ProcessInstance;
import vaani.internal.ProcessInstanceBash;
import vaani.internal.application.DotDesktopIndexer;
import vaani.internal.application.Result;

/**
 *
 * @author sourcemorph
 */

/*earlier the interface "ActionManager" was named "ApplicationManager"
 * however to make the naming more apt, it was renamed, and this class
 * represents the class that handles the application module of Vaani*/
public class ApplicationManager extends GenericManagerBashType {

    public ApplicationManager(List<String> arguments) {
        List<Result> results = DotDesktopIndexer.searchApplication(arguments);
        instances = new LinkedList<ProcessInstance>();
        Collections.sort(results);
        for(Result r : results) {
            instances.add(createProcessInstance(r));
        }
    }

    public ProcessInstanceBash createProcessInstance(Result result) {
        return new ProcessInstanceBash("Open the application " + result.getName(), "xdg-open " + result.getDotDesktopFile());
    }
}